<template>
	<view class="fa">
		<u-navbar title="课程审核" :safeAreaInsetTop="true" :autoBack="true">
			<view class="u-nav-slot" slot="right">
				<view class="flex align-c arrow-right" @click="open">
					<image src="/static/home/sort-icon.png" mode="aspectFill" class="screen" />
					<view class="">{{ typeIndex == 1?'按公开': '按私教' }}</view>
				</view>
			</view>
		</u-navbar>
		
		<view class="between align-c tabs" :style="{top: customBar + 44 + 'px'}">
			<view class="tabs_item" v-for="(v,i) in navdatas" :key="i" @click="checkNav(v.type)">
				<view class="item-name" :class="{'act': status === v.type}" >{{ v.name }}</view>
				<view class="tabs_line" :class="{'tabs_line_act': status === v.type}"></view>
			</view>
		</view>

		<view :style="{paddingTop: customBar + 88 +'px'}">
			<view class="course" v-for="(v,i) in list" :key="i">
				<view class="course_content flex" @click="toDetail(v)">
					<image :src="$img(v.cover)" mode="aspectFill" class="course_content_img" />
					<view class="f1 between column">
						<view class="">
							<view class="between align-c">
								<view class="fw-b">{{ v.title }}</view>
								<view class="course_status" :class="{'red': v.status < 3 }">{{ v.status == 1?'审核中':(v.status == 2?'已驳回':'已通过') }}</view>
							</view>
							<view class="course_content_label">时间：{{ v.start_at }}</view>
						</view>
						<view class="course_content_price" v-if="typeIndex != 1">
							<text class="symbol">￥</text>
							<text class="fw-b">{{ v.price }}</text>
							<text class="util">/节</text>
						</view>
					</view>
				</view>
				<view class="reject-reason" v-if="v.status == 2">
					<view class="">驳回原因：</view>
					<view class="reject-reason_info">{{ v.reson }}</view>
				</view>
			</view>
		</view>
		
		<u-popup :show="show" :round="10" mode="bottom" @close="close" @open="open">
			<view class="item_box">
				<view class="item" v-for="(item,index) in typeList" :key="index" @click="checkType(item)">{{ item.name }}</view>
				<view class="item_red" @click="close">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				allChecked: false,
				status: '',
				customBar: 0,
				statusHeight: 0,
				navdatas: [
					{
						name: '全部',
						type: '',
					}, {
						name: '审核中',
						type: 1,
					}, {
						name: '已驳回',
						type: 2,
					}, {
						name: '已通过',
						type: 3,
					},
				],
				list:[],
				show: false,
				typeList: [
					{
						name: '按公开课',
						type: 1
					},
					{
						name: '按私教课',
						type: 2
					}
				],
				typeIndex: 1,
				shop_id: '',
				page: 1,
				last_page: 1,
			}
		},
		onLoad(e) {
			if(e&&e.type) {
				this.status = parseInt(e.type);
			}else if(e&&e.type==='') {
				this.status = '';
			}
			this.getSystemInfo();
			this.shop_id = uni.getStorageSync('shopId');
		},
		onShow() {
			this.getCourse();
		},
		methods: {
			getSystemInfo() {
				uni.getSystemInfo({
					success: (e) => {
						this.customBar = e.statusBarHeight;
					}
				})
			},
			checkNav(a){
				this.status=a;
				this.getCourse();
			},
			open() {
				this.show = true;
			},
			close() {
				this.show = false;
			},
			checkType(v) {
				this.typeIndex = v.type;
				this.getCourse();
				this.show = false;
			},
			async getCourse() {
				let res = await this.$api.get('staff/course/checks', {
					type: this.typeIndex,
					status: this.status,
					page: this.page,
					shop_id: this.shop_id,
				});
				if(res.code == 200) {
					this.last_page = parseInt(res.data.to)/parseInt(res.data.per_page);
					if(this.page == 1) {
						this.list = res.data.data;
					}else {
						this.list.push(...res.data.data);
					}
				}
			},
			toDetail(v) {
				if(v.status == 1) {
					return false;
				}
				this.$to(`/pages/home/overt/course_detail?id=${v.id}&type=${v.type}`);
			},
		}
	}
</script>

<style>
	page {
		box-sizing: border-box;
		background-color: #F7F7F7;
	}
</style>

<style lang="scss">
	.arrow-right {
		font-size: 24rpx;
		.screen {
			width: 29rpx;
			height: 29rpx;
			margin-right: 10rpx;
		}
	}
	
	.tabs {
		background-color: #FFF;
		height: 44px;
		line-height: 44px;
		padding: 0 40rpx;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 999;
		&_item {
			font-size: 27rpx;
			color: #B3B3B3;
		}
		.item-name {
			line-height: 54rpx;
		}
		.act {
			color: #F17816;
		}
		&_line {
			height: 7rpx;
			background: #ffffff;
			width: 53rpx;
			bottom: 2px;
			border-radius: 100px;
			transition-property: transform;
			transition-duration: 300ms;
			margin: 0 auto;
		}
		&_line_act {
			background-color: #F17816;
		}
	}

	button {
		margin: 0
	}

	.course {
		font-size: 27rpx;
		padding: 0 20rpx;
		background-color: #fff;
		margin: 27rpx;
		border-radius: 20rpx;
		&_status {
			color: #B3B3B3;
		}
		.red {
			color: #F51818;
		}
		&_content {
			padding: 20rpx 0;
			&_img {
				width: 160rpx;
				height: 160rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
			}
			&_label {
				color: #B3B3B3;
				font-size: 24rpx;
				margin-top: 8rpx;
			}
			&_price {
				color: #F51818;
				.symbol {
					font-size: 27rpx;
				}
				.fw-b {
					font-size: 32rpx;
				}
				.util {
					font-size: 24rpx;
				}
			}
		}
		&_bottom {
			padding-top: 10rpx;
			padding-bottom: 30rpx;
			justify-content: flex-end;
			.btn {
				margin: 0;
				padding: 0;
				padding: 0 24rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				height: 47rpx;
				line-height: 47rpx;
				min-width: 93rpx;
				text-align: center;
				margin-left: 24rpx;
			}
			.org_btn {
				background-color: #F17816;
				color: #fff;
			}
		}
	}
	
	.reject-reason {
		font-size: 27rpx;
		padding-bottom: 32rpx;
		&_info {
			margin-top: 20rpx;
			padding: 16rpx 22rpx;
			font-size: 24rpx;
			background-color: #FFF4F4;
			color: #EA3434;
			min-height: 100rpx;
		}
	}
	.publish-box {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: #FFF;
		font-size: 27rpx;
		.check_box {
			width: 33rpx;
			height: 33rpx;
			margin: 0 30rpx;
		}
		.publish-btn {
			margin: 0;
			padding: 0;
			background-color: #F17816;
			width: 187rpx;
			text-align: center;
			color: #FFF;
			height: 93rpx;
			line-height: 93rpx;
			border-radius: 0;
			font-size: 27rpx;
		}
	}
</style>
